<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item label="申请时间">
              <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.createTime_begin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.createTime_end"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户昵称">
              <a-input placeholder="请输入用户昵称" v-model="queryParam.nickname"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="银行卡号">
              <j-input placeholder="请输入银行卡号" v-model="queryParam.bankCard"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="提现状态">
              <j-dict-select-tag v-model="queryParam.status" dictCode="examine_status" placeholder="全部" clearable/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button type="primary" icon="download" @click="handleExportXls('分销员提现')"
                        style="margin-left: 8px">导出</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns"
               :dataSource="dataSource" :pagination="ipagination"
               :loading="loading" class="j-table-force-wrap" @change="handleTableChange">

        <template slot="feeSlot" slot-scope="text, record">
          <span>
            {{ record.originalPrice - record.price }}
          </span>
        </template>
        <template slot="status" slot-scope="text, record">
          <a-tag color="orange" v-if="text==1">
            等待审核
          </a-tag>
          <a-tag color="green" v-if="text==2">
            审核通过
          </a-tag>
          <a-tag color="red" v-if="text==3">
            审核拒绝
          </a-tag>
          <!--          <span v-if="record.status===1" style="color:#9d9d00;">
                      <a-icon type="history" style="margin-right: 3px;color:#9d9d00;" />
                      {{ text }}
                    </span>
                    <span v-if="record.status===2" style="color:green;">
                      <a-icon type="check-circle" theme="twoTone" two-tone-color="#52c41a" style="margin-right: 3px;" />
                      {{ text }}
                    </span>
                    <span v-if="record.status===3" style="color:red;">
                      <a-icon type="close-circle" theme="twoTone" two-tone-color="red" style="margin-right: 3px;" />
                      {{ text }}
                    </span>-->
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="55px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a-popconfirm title="确定通过吗?" @confirm="() => {
            reason = undefined;
            handlePass(record.id, 2);
          }" v-if="record.status == 1">
            <a>通过</a>
          </a-popconfirm>

          <a-divider type="vertical" v-if="record.status == 1"/>

          <a-popconfirm title="确定拒绝吗?" @confirm="() => {
            modelVal = record;
            reason = undefined;
            showRefuse = true;
          }" v-if="record.status == 1">
            <a>拒绝</a>
          </a-popconfirm>

        </span>

      </a-table>
    </div>

    <a-modal v-model="showRefuse" title="拒绝说明" @ok="() => {
            showRefuse = false;
            handlePass(modelVal.id, 3)
          }">
      <a-textarea v-model="reason" placeholder="建议填写拒绝原因" :auto-size="{ minRows: 4, maxRows: 5 }"/>
    </a-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import JDate from '@/components/jeecg/JDate.vue'
import JInput from '@/components/jeecg/JInput'
import {postAction} from "@api/manage"

export default {
  name: 'SmsSupplierCashLogList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDate,
    JInput
  },
  data() {
    return {
      description: '商家提现审核',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '提现单号',
          align: "center",
          dataIndex: 'id'
        },
        {
          title: '用户昵称',
          align: "center",
          dataIndex: 'uid_dictText'
        },
        {
          title: '用户昵称',
          align: "center",
          dataIndex: 'phone'
        },
        {
          title: '提现原金额',
          align: "center",
          dataIndex: 'originalPrice'
        },
        {
          title: '手续费',
          align: "center",
          scopedSlots: {customRender: 'feeSlot'}
        },
        {
          title: '实际到帐金额',
          align: "center",
          dataIndex: 'price'
        },
        {
          title: '银行名称',
          align: "center",
          dataIndex: 'bankName'
        },
        {
          title: '银行卡号',
          align: "center",
          dataIndex: 'bankCard'
        },
        {
          title: '提现状态',
          align: "center",
          dataIndex: 'status',
          scopedSlots: {customRender: 'status'}
        },
        {
          title: '申请时间',
          align: "center",
          width: 100,
          sorter: true,
          dataIndex: 'createTime'
        },
        {
          title: '处理时间',
          align: "center",
          width: 100,
          sorter: true,
          dataIndex: 'handleTime'
        },
        {
          title: '处理员',
          align: "center",
          dataIndex: 'handleName'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        list: "/member/umsCashLog/list",
        delete: "/member/umsCashLog/delete",
        deleteBatch: "/member/umsCashLog/deleteBatch",
        exportXlsUrl: "/member/umsCashLog/exportXls",
        importExcelUrl: "member/umsCashLog/importExcel",
      },
      dictOptions: {},
      modelVal: {},
      reason: undefined,
      showRefuse: false,
    }
  },
  created() {
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {
    },

    handlePass(id, status) {
      let that = this
      postAction("/member/umsCashLog/examine", {id: id, status: status, reason: this.reason}).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.loadData()
        } else {
          that.$message.warning(res.message)
        }
      })
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>